//
//  DDSoundDetalisTableViewCell.m
//  ialone
//
//  Created by lanou on 16/1/13.
//  Copyright © 2016年 JasperSong. All rights reserved.
//

#import "DDSoundDetalisTableViewCell.h"
#import "UIImageView+WebCache.h"
@implementation DDSoundDetalisTableViewCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        [self addSubviews];
    }
    
    return self;
    
}


- (void)addSubviews
{
    // 头像
    self.avatar = [[UIImageView alloc] initWithFrame:CGRectMake(20, 20, 50, 50)];
    self.avatar.layer.cornerRadius = 25;
    self.avatar.layer.masksToBounds = YES;
  //  self.avatar.backgroundColor = [UIColor grayColor];
    [self.contentView addSubview:self.avatar];
    
    // 昵称
    self.nickname = [[UILabel alloc] initWithFrame:CGRectMake(self.avatar.frame.origin.x + self.avatar.frame.size.width + 10, self.avatar.frame.origin.y, 120, 30)];
  //  self.nickname.backgroundColor = [UIColor grayColor];
    [self.contentView addSubview:self.nickname];
    
    // 喜欢
    self.like = [UIButton buttonWithType:(UIButtonTypeCustom)];
    self.like.frame = CGRectMake(kScreenWidth - self.avatar.frame.origin.x - self.nickname.frame.size.height, self.nickname.frame.origin.y, self.nickname.frame.size.height, self.nickname.frame.size.height);
  //  self.like.backgroundColor = [UIColor grayColor];
    [self.like setImage:[UIImage imageNamed:@"shoucang"] forState:(UIControlStateNormal)];
    [self.contentView addSubview:self.like];
    
    // 评论
    self.content = [[UILabel alloc] initWithFrame:CGRectMake(self.nickname.frame.origin.x, self.nickname.frame.origin.y + self.nickname.frame.size.height + 10, kScreenWidth - self.nickname.frame.origin.x * 2, kScreenHeight)];
    self.content.numberOfLines = -1;
    self.content.font = [UIFont systemFontOfSize:16];
  //
  //  self.content.backgroundColor = [UIColor grayColor];
    [self.contentView addSubview:self.content];
    
    // 评论时间
    self.update_time = [[UILabel alloc] initWithFrame:CGRectMake(self.avatar.frame.origin.x, self.content.frame.origin.y + self.content.frame.size.height + 20, 200, 30)];
//    self.update_time = [[UILabel alloc] initWithFrame:CGRectMake(self.nickname.frame.origin.x,, 200, 30)];
    self.update_time.font = [UIFont systemFontOfSize:12];
    self.update_time.backgroundColor = [UIColor grayColor];
  //  [self.contentView addSubview:self.update_time];
    
    
}

- (void)setModel:(DDSoundDetalisModel *)model
{
    _model = model;
    
    // 头像
    [self.avatar sd_setImageWithURL:[NSURL URLWithString:model.avatar]];
    // 昵称
    self.nickname.text = model.nickname;
    // 评论
    CGFloat content = [DDSoundDetalisTableViewCell cellHeightForModel:model];
    CGRect frame = self.content.frame;
    frame.size.height = content;
    self.content.frame = frame;
    self.content.text = model.content;
    
    self.update_time.text = model.update_time;
    
}


+ (CGFloat)cellHeightForModel:(DDSoundDetalisModel *)model
{
    
    
   // 创建字体大小的字典
   NSDictionary *fontDic = @{NSFontAttributeName:[UIFont systemFontOfSize:16]};
   // 计算字符串高度
   CGRect textRect = [model.content boundingRectWithSize:CGSizeMake(kScreenWidth - 160, CGFLOAT_MAX) options:(NSStringDrawingUsesLineFragmentOrigin) attributes:fontDic context:nil];
  return textRect.size.height;

}










- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
